export function sortColors(nums: number[]): void {
    let p0 = 0;
    let p2 = nums.length - 1;

    for (let i = 0; i <= p2; i++) {
        while(nums[i] === 2 && i<= p2) {
            swap(nums, i, p2);
            p2--;
        }

        if (nums[i] === 0) {
            swap(nums, i, p0);
            p0++;
        }
    }
};
function swap (nums: number[], pos1: number, pos2: number) {
    const temp = nums[pos1];
    nums[pos1] = nums[pos2];
    nums[pos2] = temp;
}